package view;
import geo2d.pt;
import model.Dat;
import model.Topic;
import processing.core.*;; 

public class TopicView extends PApplet{
	int width, height; 
	boolean update = true; 
	boolean move = false; 
	Topic group ; 
	public TopicView(int w, int h, int y){
		width = w; height = h; 
		group = Dat.createTopic(w, h, y); 
	}
	public void setup(){	
		size(width, height, P2D); 
		textMode(SCREEN);
		textAlign(CENTER);
		Topic.setFontandColor(this); 
		//smooth(); 
	}
	public void draw(){
		background(255); 
		noStroke(); 
		if (move) st.moveWithMouse(this); 
		group.showTopics(this); 
		if (update) group.update(); 
	}
	public void mousePressed(){
		if (key=='e'){
			Topic t = group.selectTopic(pt.mouse(this)); 
			t.expand(); 
		}
		if (key=='d'){
			st = group.select(pt.mouse(this)); 
			if (st!=null) move = true; 
		}
	}
	Topic st; 
	public void mouseReleased(){
		move = false; st = null; 
	}
	public void keyPressed(){
		if (key=='a'){
			update=!update; 
			print("turn "); 
			if (update) print("on "); 
			else print("off "); 
			println("update"); 
		}
		if (key=='b'){
		}
		if (key=='c'){
		
		}
		if (key=='d'){
			println("drag around"); 
		}	
		if (key=='e'){
			println("expand or collapse"); 
		}
		if (key=='x'){
			println("save a picture"); 
			saveFrame("pic/pic-####.png"); 
		}
		
	}
}
